package com.bobo.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@SpringBootApplication
@RestController
public class DemoApplication {

	public static void main(String[] args) {
		SpringApplication.run(DemoApplication.class, args);
	}

	@GetMapping("/hello")
	public String hello(
		@RequestParam(value = "name", defaultValue = "World") String name) {
		return String.format("Hello2 %s!", name);
	}

	@GetMapping("/data")
	public TData data(@RequestParam(value = "name", defaultValue = "world") String name) {
		return new TData(10, String.format("Hello %s", name));
	}

	@GetMapping("/ldata")
	public List<TData> ldata(@RequestParam(value = "name", defaultValue = "world") String name) {
		List<TData> ld = new ArrayList<TData>();
		ld.add(new TData(10, String.format("Hello %s", name)));
		ld.add(new TData(12, String.format("Hello %s", name)));

		return ld;
	}

	@GetMapping("/lstr")
	public List<String> lstr(@RequestParam(value = "name", defaultValue = "world") String name) {
		List<String> ld = new ArrayList<String>();
		ld.add("abc");
		ld.add("efg....sss");

		return ld;
	}

	@GetMapping("/cdata")
	public HashMap<String, List<String>> cdata(@RequestParam(value = "name", defaultValue = "world") String name) {
		HashMap<String, List<String>> map_data = new HashMap<String, List<String>>();

		map_data.put("key1", new ArrayList<String>());
		map_data.get("key1").add("aaa11");
		map_data.get("key1").add("aaa22");
		map_data.get("key1").add("aaa33");

		map_data.put("key2", new ArrayList<String>());
		map_data.get("key2").add("baaa11");
		map_data.get("key2").add("baaa22");
		map_data.get("key2").add("baaa33");

		return map_data;
	}

	@GetMapping("/gdata")
	public GData gdata(@RequestParam(value = "name", defaultValue = "world") String name) {
		GData gdata = new GData(name);
		gdata.addData(new TData(10, String.format("Hello %s", name)));
		gdata.addData(new TData(11, String.format("Hello %s", name)));
		gdata.addData(new TData(12, String.format("Hello %s", name)));

		return gdata;
	}
}
